package service

import (
	"github.com/casbin/casbin/v2"
	"github.com/casbin/redis-adapter/v2"
	"go.uber.org/zap"
	"log"
)

func InitCasbin() {
	var a *redisadapter.Adapter
	if len(Conf.Redis.Password) > 0 {
		a = redisadapter.NewAdapterWithPassword("tcp", Conf.Redis.Addr, Conf.Redis.Password)
	} else {
		a = redisadapter.NewAdapter("tcp", Conf.Redis.Addr)
	}
	e, err := casbin.NewEnforcer("conf/model.conf", a)
	if err != nil {
		panic(err)
	}
	err = e.LoadPolicy()
	if err != nil {
		log.Fatal()
	}
	E = e
	zap.L().Info("Casbin 启动ok..")
}
